package cn.edu.sjtu.software.sjtucontacts.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.edu.sjtu.software.sjtucontacts.util.ContactIDGenerator;
import cn.edu.sjtu.software.sjtucontacts.util.ListUtil;
import cn.edu.sjtu.software.sjtucontacts.util.StringUtil;

public class Contact implements Serializable{
	private int id;
	private int groupid;
	private String firstName;
	private String lastName;
	private String email;
	private String homePage;
	private List<String> businessPhoneList;
	private List<String> homePhoneList;
	private List<String> mobilePhoneList;
	private String defaultPhoneNumber;
	private String homeAddress;
	private String workAddress;
	private String job;
	private String birthday;
	private String portraitUrl;
	private String qq;
	private String msn;
	private String remarks;
	private List<Customization> customizationList;
	
	public Contact (){
		businessPhoneList = new ArrayList<String>();
		homePhoneList = new ArrayList<String>();
		mobilePhoneList = new ArrayList<String>();
		
		customizationList = new ArrayList<Customization>();
		
		id = ContactIDGenerator.nextId();
		groupid = StringUtil.GROUP_NOT_IDENTIFIED_ID;
		firstName = "";
		lastName = "";
		email = "";
		homePage = "";	
		defaultPhoneNumber = "";
		homeAddress = "";
		workAddress = "";
		job = "";
		birthday = "";
		portraitUrl = "";
		qq = "";
		msn = "";
		remarks = "";
	}
	

	public Contact(int id, int groupid, String firstName, String lastName,
			String email, String homePage, List<String> businessPhoneList,
			List<String> homePhoneList, List<String> mobilePhoneList,
			String defaultPhoneNumber, String homeAddress, String workAddress,
			String job, String birthday, String portraitUrl, String qq,
			String msn, String remarks, List<Customization> customizationList) {
		super();
		this.id = id;
		this.groupid = groupid;
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.homePage = homePage;
		this.businessPhoneList = businessPhoneList;
		this.homePhoneList = homePhoneList;
		this.mobilePhoneList = mobilePhoneList;
		this.defaultPhoneNumber = defaultPhoneNumber;
		this.homeAddress = homeAddress;
		this.workAddress = workAddress;
		this.job = job;
		this.birthday = birthday;
		this.portraitUrl = portraitUrl;
		this.qq = qq;
		this.msn = msn;
		this.remarks = remarks;
		this.customizationList = customizationList;
	}

	public List<String> getBusinessPhoneList() {
		return businessPhoneList;
	}

	public void setBusinessPhoneList(List<String> businessPhoneList) {
		this.businessPhoneList = businessPhoneList;
	}
	
	public void addBusinessPhone(String businessPhone)
	{
		this.businessPhoneList.add(businessPhone);
	}

	public List<String> getHomePhoneList() {
		return homePhoneList;
	}

	public void setHomePhoneList(List<String> homePhoneList) {
		this.homePhoneList = homePhoneList;
	}
	
	public void addHomePhone(String homePhone)
	{
		this.homePhoneList.add(homePhone);
	}

	public List<String> getMobilePhoneList() {
		return mobilePhoneList;
	}

	public void setMobilePhoneList(List<String> mobilePhoneList) {
		this.mobilePhoneList = mobilePhoneList;
	}
	
	public void addMobilePhone(String mobilePhone)
	{
		this.mobilePhoneList.add(mobilePhone);
	}

	public String getDefaultPhoneNumber() {
		return defaultPhoneNumber;
	}

	public void setDefaultPhoneNumber(String defaultPhoneNumber) {
		this.defaultPhoneNumber = defaultPhoneNumber;
	}

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	
	public int getGroupId() {
		return groupid;
	}


	/*
	 * This method is only used when initialization
	 */
	public void setGroupId(int groupid, int n) {
		this.groupid = groupid;
	}
	
	/*
	 * How to invoke this method when initialize a contact???
	 */
	public void setGroupId(int groupid) {
		if (this.groupid != groupid) {
			ListUtil.getInstance().changeContactToGroup(id, this.groupid, groupid);
		}
		this.groupid = groupid;
	}
		

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getJob() {
		return job;
	}
	public void setJob(String job) {
		this.job = job;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getHomePage() {
		return homePage;
	}
	public void setHomePage(String homePage) {
		this.homePage = homePage;
	}
	public String getBirthday() {
		return birthday;
	}
	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getPortraitUrl() {
		return portraitUrl;
	}

	public void setPortraitUrl(String portraitUrl) {
		this.portraitUrl = portraitUrl;
	}

	public String getHomeAddress() {
		return homeAddress;
	}


	public void setHomeAddress(String homeAddress) {
		this.homeAddress = homeAddress;
	}

	public String getWorkAddress() {
		return workAddress;
	}

	public void setWorkAddress(String workAddress) {
		this.workAddress = workAddress;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getMsn() {
		return msn;
	}

	public void setMsn(String msn) {
		this.msn = msn;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}	
	
	public List<Customization> getCustomizationList() {
		return customizationList;
	}

	public void setCustomizationList(List<Customization> customizationList) {
		this.customizationList = customizationList;
	}
	
	public void addCustomization(Customization c)
	{
		this.customizationList.add(c);
	}
	
	public void addCustomziation(String attribute, String value)
	{
		this.customizationList.add(new Customization(attribute, value));
	}
	
	public void clearMobilePhoneList()
	{
		this.mobilePhoneList.clear();
	}
	
	public void clearHomePhoneList()
	{
		this.homePhoneList.clear();
	}
	
	public void clearBusinessPhoneList()
	{
		this.businessPhoneList.clear();
	}
	
	public void clearCustomization()
	{
		this.customizationList.clear();
	}

	public class Customization implements Serializable{
		public String attribute;
		public String value;
		
		public Customization(){}
		
		public Customization(String attribute, String value)
		{
			this.attribute = attribute;
			this.value = value;
		}
	}
}
